<template>
<h2>房型新增</h2>

<table class="table table-bordered">
    <tr>
        <td>类型名称</td>
        <td>
            <input type="text" v-model="info.typename"/>
        </td>
    </tr>
    <tr>
        <td>门市价格</td>
        <td>
            <input type="text" v-model="info.price"/>元
        </td>
    </tr>
    <tr>
        <td>房间大小</td>
        <td>
            <input type="text" v-model="info.size"/>平米
        </td> 
    </tr>
    <tr>
        <td>状态</td>
        <td>
            <input type="radio" :value="true" v-model="info.tState"/>启用
            <input type="radio" :value="false" v-model="info.tState"/>禁用
        </td> 
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" value="提交" class="btn btn-info" @click="Add"/>
        </td>
    </tr>
</table>



</template>
    
<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';
const router=useRouter()

const info=ref({
    typename:'',
    price:'',
    size:'',
    tState:true
})

const Add=()=>{
    var obj={
        typename:info.value.typename,
        price:info.value.price,
        size:info.value.size,
        tState:info.value.tState
    }
    axios.post('https://localhost:7173/api/Room/RoomTypeAdd',obj)

    .then(res=>{
        if(res.data==-1){
            alert('该房型已存在请勿重复添加')
        }
        else if(res.data>0){
            alert('设置成功')
            router.push('/RoomTypeShow')
        }
        else{
            alert('设置失败')
        }
    })
    .catch(err=>{
        console.log(err)
    })
}


</script>